<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="common/header.jsp" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>svn补丁生产工具</title>
</head>
<style>
.list-group li{
	height:10rem;
	width:20rem;
	margin-right:3rem;
	margin-bottom:3rem;
	float:left;
}
</style>

<body>
<!-- 顶部导航条 -->
<nav class="navbar navbar-default navbar-static-top">
	<div class="container">
		
		<ul class="nav navbar-nav">
	        <li class="dropdown">
				<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">日志<span class="caret"></span></a>
				<ul class="dropdown-menu">
					<c:forEach items="${pros}" var="item">
					<li><a href="javascript:log('${item.id}','${item.name}');">${item.name}</a></li>
					</c:forEach>
				</ul>
	        </li>
		</ul>
		<button type="button" class="btn btn-default navbar-btn" style="float:right;" onclick="edit(0)">新增</button>
	</div>
</nav>

<div style="margin:3rem 10rem">
	<ul class="list-group">
		<c:forEach items="${pros}" var="item" varStatus="status">
			<c:choose>
				<c:when test="${status.index%4==0}"><li class="list-group-item list-group-item-success"></c:when>
				<c:when test="${status.index%4==1}"><li class="list-group-item list-group-item-info"></c:when>
				<c:when test="${status.index%4==2}"><li class="list-group-item list-group-item-warning"></c:when>
				<c:when test="${status.index%4==3}"><li class="list-group-item list-group-item-danger"></c:when>
			</c:choose>
			项目名称：${item.name}<br/>
			最近补丁时间：<fmt:formatDate value="${item.lastUpdateTime}" pattern="yyyyMMdd HH:mm"/><br/><br/>
			<div class="btn-group btn-group-justified" role="group" aria-label="...">
				<div class="btn-group" role="group">
			    	<button type="button" class="btn btn-default" onclick="doPatch(${item.id})">打补丁</button>
				</div>
				<div class="btn-group" role="group">
					<button type="button" class="btn btn-default" onclick="edit(${item.id})">编辑</button>
				</div>
				<div class="btn-group" role="group">
			    	<button type="button" class="btn btn-default" onclick="delById(${item.id},this)">删除</button>
				</div>
			</div>
		</c:forEach>
	</ul>
</div>

</body>
</html>
<script>

var winIndex;

function edit(id){
	layer.open({
		title:'新增一个项目',
		type: 2,
		area: ['700px', '450px'],
		fixed: false, //不固定
		maxmin: true,
		content: '${webRoot}/svn/te?id='+id,
		btn: ['提交', '取消'],
		yes: function(index, layero){
			winIndex = index;
			var subDocument = $(layero).find('iframe')[0].contentWindow;
			subDocument.submit();
		}
	});
}

function doPatch(id){
	layer.open({
		title:'打补丁',
		type: 2,
		area: ['60rem', '50rem'],
		fixed: false, //不固定
		maxmin: true,
		content: '${webRoot}/patch/tpp?projectId='+id,
		btn: ['打包', '取消'],
		yes: function(index, layero){
			winIndex = index;
			var subDocument = $(layero).find('iframe')[0].contentWindow;
			subDocument.doPatch();
		}
	});
}

function winClose(refresh){
	layer.close(winIndex);
	if(refresh){
		window.location.reload(true);
	}
}

function delById(id, s){
	layer.msg('确定删除？', {
		time: 0 //不自动关闭
		,btn: ['删吧', '不删了']
		,yes: function(index){
			layer.close(index);
		    $.ajax({
		    	url:'${webRoot}/svn/d',
		    	type:'post',
		    	data:{'id':id},
		    	success:function(data){
		    		if(data.success){
		    			layer.msg('数据删除成功',{time:2000},function(){$(s).parent().parent().parent().remove();});
		    		}else{
		    			layer.alert(data.msg, {icon: 6});
		    		}
		    	}
		    });
		}
	});
}

function log(projectId, projectName){
	layer.open({
		title: projectName+'日志详情',
		type: 2,
		area: ['60rem', '50rem'],
		fixed: false, //不固定
		maxmin: true,
		content: '${webRoot}/log/td?project.id='+projectId,
		btn: ['关闭']
	});
}

</script>